package modelLayer;
import java.util.*;

public class RentContainer {
    private static RentContainer instance;
    private ArrayList<Rent> rents;
    private int nextId;
    
    private RentContainer(){
        rents = new ArrayList<>();
   }
   
    public static RentContainer getInstance(){
        if(instance == null){
            instance = new RentContainer();
        }
        return instance;
   }
   
    public void addRent(Rent rent){
        this.nextId++;
        rent.setRentId(this.nextId);
        rents.add(rent);
   }
   
   public Rent findRent(int id){
        boolean found=false;
        int index=0;
        System.out.println(rents.size());
        while(index < rents.size() && !found) {
            Rent rent = rents.get(index);
            if(rent.getRentId() == id){
                found=true;
            }
            else {
                index++;            
            }
        }
        if(found){
            return rents.get(index);
        }
        else{
            return null;
        }
   }
   
   public ArrayList<Rent> rentsByMonth(String month) {
       ArrayList<Rent> monthRents = new ArrayList<>();
       for (Rent rent : rents) {
           if(rent.getRentDate().substring(3,5).equals(month)) {
               monthRents.add(rent);
           }
       }
       return monthRents;
    }
}